<template>
    <el-card shadow="hover">
    <template #header>
      <div class="card-header">
        <el-button class="button" color="#1baeae">+ 增加商品</el-button>
      </div>
    </template>
    <el-table v-loading="state.loading" ref="multipleTableRef" :data="state.tableData" style="width: 100%" @selection-change="handleSelectionChange">
      <el-table-column type="selection" />
      <el-table-column property="goodsId" label="商品编号" />
      <el-table-column property="goodsName" label="商品名称" />
      <el-table-column property="goodsIntro" label="商品简介" />
       <el-table-column label="商品图片">
        <template #default="scope">
          <el-image style="width: 100px; height: 100px" :src="scope.row.goodsCoverImg" />
        </template>
      </el-table-column>
      <el-table-column property="stockNum" label="商品库存" />
      <el-table-column property="sellingPrice" label="商品售价" />
      <el-table-column property="address" label="Address" show-overflow-tooltip />
    </el-table>
  </el-card>
  <el-pagination background layout="prev, pager, next" :total="state.total" :page-size="state.pageSize"
      @prev-click="prevClick" @next-click="nextClick" @current-change="currentChange" />
</template>

<script>
  export default {
    name: 'commodityAdministration',
  }
</script>
<script setup>
  import { onBeforeMount } from 'vue';
  import api from '@/http'
  import {reactive} from 'vue';
  import {
    ElMessage
  } from 'element-plus'
  const state = reactive({
    tableData: [],
    total: 0,
    pageSize: 10,
    currentPage: 1,
    loading: false,
  })
  onBeforeMount(() => {
    init();
  })
  // 渲染列表
  const init = async () => {
    state.loading = true;
    const {
      data,
      resultCode
    } = await api.commodity.goodsList(state.currentPage, state.pageSize);
    if (resultCode === 200) {
      state.tableData = data.list;
      state.total = data.totalCount;
      state.currentPage = data.currPage;
      state.pageSize = data.pageSize;
      state.loading = false;
    } else {
      ElMessage({
        showClose: true,
        message: '数据渲染失败，请稍后再试！！',
        type: 'error',
      })
      state.loading = false;
    }
  }
</script>

<style lang="less" scoped>
  .button {
    color: #fff;
  }
</style>